<script setup>
import {list_favorite} from "@/apis/v1/favorite/favorite.js";

const favoriteList = ref([]);
const goLink = (child) => {
  window.open(child.url, "_blank");
};
onMounted(() => {
  list_favorite().then(res => {
    favoriteList.value = res.result;
  });
});
</script>

<template>
  <div class="content my-animation-hideToShow">
    <div class="site box-shadow" v-for="item in favoriteList" :key="item.id">
      <div class="title">{{ item.name }}</div>
      <ul>
        <li class="my-animation-slide-bottom" v-for="child in item.children"
            :key="child.id" @click="goLink(child)">
          <div class="item">
                <span class="logo">
                  <img style="object-fit: cover;" :src="child.logo" alt="">
                </span>
            <span class="name">{{ child.name }}</span>
          </div>
          <div class="info">{{ child.info }}</div>
        </li>
      </ul>
    </div>
  </div>
</template>

<style scoped lang="less">
.content {
  margin-top: 40px;

  .site {
    color: var(--text-color);
    border-radius: 5px;
    background-color: var(--background-color);

    .title {
      height: 40px;
      line-height: 40px;
      color: #000;
      font-weight: 700;
      text-align: center;
      background-color: #94ce6f61;
      border-top-right-radius: 5px;
      border-top-left-radius: 5px;
    }

    ul {
      padding: 10px;
      display: grid;
      list-style: none;
      grid-template-columns: repeat(5, 1fr);

      li {
        cursor: pointer;
        margin-bottom: 10px;
        padding: 10px;
        font-size: 15px;

        &:hover {
          background-color: #3a8ee62e;
          border-radius: 10px
        }

        &:hover .name {
          color: #d93131
        }

        .item {
          margin-bottom: 5px;

          .logo {
            border-radius: 50%;
            vertical-align: middle;
            margin-right: 10px;

            img {
              width: 40px;
              height: 40px;
              border-radius: 50%;
            }
          }

          .name {
            font-weight: 700;
          }
        }

        .info {
          color: #c3c3c3;
          width: 90%;
          word-break: break-all;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          overflow: hidden;
        }
      }
    }
  }
}
</style>